package com.myapp.api.mapper;

import com.myapp.api.entity.Student;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface StudentMapper {
    @Delete({
        "delete from student",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into student (id, Sid, ",
        "Mid, Sname, Sex, ",
            "Pwd, Phone, LoginTime, ",
            "LoginIP, Role, CreateTime, ",
            "UpdateTime, AuthToken)",
            "values (#{id,jdbcType=INTEGER}, #{sid,jdbcType=VARCHAR}, ",
            "#{mid,jdbcType=VARCHAR}, #{sname,jdbcType=VARCHAR}, #{sex,jdbcType=VARCHAR}, ",
            "#{pwd,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{logintime,jdbcType=TIMESTAMP}, ",
            "#{loginip,jdbcType=VARCHAR}, #{role,jdbcType=VARCHAR}, #{createtime,jdbcType=TIMESTAMP}, ",
            "#{updatetime,jdbcType=TIMESTAMP}, #{authtoken,jdbcType=LONGVARCHAR})"
    })
    int insert(Student record);

    @InsertProvider(type=StudentSqlProvider.class, method="insertSelective")
    int insertSelective(Student record);

    @Select({
        "select",
            "id, Sid, Mid, Sname, Sex, Pwd, Phone, LoginTime, LoginIP, Role, CreateTime, ",
            "UpdateTime, AuthToken",
        "from student",
            "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Sid", property = "sid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "Mid", property = "mid", jdbcType = JdbcType.VARCHAR),
        @Result(column="Sname", property="sname", jdbcType=JdbcType.VARCHAR),
        @Result(column="Sex", property="sex", jdbcType=JdbcType.VARCHAR),
        @Result(column="Pwd", property="pwd", jdbcType=JdbcType.VARCHAR),
        @Result(column="Phone", property="phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="LoginTime", property="logintime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="LoginIP", property="loginip", jdbcType=JdbcType.VARCHAR),
            @Result(column = "Role", property = "role", jdbcType = JdbcType.VARCHAR),
        @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column = "UpdateTime", property = "updatetime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "AuthToken", property = "authtoken", jdbcType = JdbcType.LONGVARCHAR)
    })
    Student selectByPrimaryKey(Integer id);

    @UpdateProvider(type=StudentSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Student record);

    @Update({
        "update student",
            "set Sid = #{sid,jdbcType=VARCHAR},",
            "Mid = #{mid,jdbcType=VARCHAR},",
          "Sname = #{sname,jdbcType=VARCHAR},",
          "Sex = #{sex,jdbcType=VARCHAR},",
          "Pwd = #{pwd,jdbcType=VARCHAR},",
          "Phone = #{phone,jdbcType=VARCHAR},",
            "LoginTime = #{logintime,jdbcType=TIMESTAMP},",
            "LoginIP = #{loginip,jdbcType=VARCHAR},",
            "Role = #{role,jdbcType=VARCHAR},",
            "CreateTime = #{createtime,jdbcType=TIMESTAMP},",
            "UpdateTime = #{updatetime,jdbcType=TIMESTAMP},",
            "AuthToken = #{authtoken,jdbcType=LONGVARCHAR}",
            "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKeyWithBLOBs(Student record);

    @Update({
            "update student",
            "set Sid = #{sid,jdbcType=VARCHAR},",
            "Mid = #{mid,jdbcType=VARCHAR},",
            "Sname = #{sname,jdbcType=VARCHAR},",
            "Sex = #{sex,jdbcType=VARCHAR},",
            "Pwd = #{pwd,jdbcType=VARCHAR},",
            "Phone = #{phone,jdbcType=VARCHAR},",
          "LoginTime = #{logintime,jdbcType=TIMESTAMP},",
          "LoginIP = #{loginip,jdbcType=VARCHAR},",
            "Role = #{role,jdbcType=VARCHAR},",
          "CreateTime = #{createtime,jdbcType=TIMESTAMP},",
          "UpdateTime = #{updatetime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Student record);

    @Select({
            "select",
            "id, Sid, Mid, Sname, Sex, Pwd, Phone, LoginTime, LoginIP, Role, CreateTime, ",
            "UpdateTime, AuthToken",
            "from student"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Sid", property = "sid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "Mid", property = "mid", jdbcType = JdbcType.VARCHAR),
            @Result(column="Sname", property="sname", jdbcType=JdbcType.VARCHAR),
            @Result(column="Sex", property="sex", jdbcType=JdbcType.VARCHAR),
            @Result(column="Pwd", property="pwd", jdbcType=JdbcType.VARCHAR),
            @Result(column="Phone", property="phone", jdbcType=JdbcType.VARCHAR),
            @Result(column="LoginTime", property="logintime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="LoginIP", property="loginip", jdbcType=JdbcType.VARCHAR),
            @Result(column = "Role", property = "role", jdbcType = JdbcType.VARCHAR),
            @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column = "UpdateTime", property = "updatetime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "AuthToken", property = "authtoken", jdbcType = JdbcType.LONGVARCHAR)
    })
    List<Student> getStudents();

    @Select({
            "select",
            "id, Sid, Mid, Sname, Sex, Pwd, Phone, LoginTime, LoginIP, Role, CreateTime, ",
            "UpdateTime, AuthToken",
            "from student",
            "where Sid = #{sid,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Sid", property = "sid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "Mid", property = "mid", jdbcType = JdbcType.VARCHAR),
            @Result(column="Sname", property="sname", jdbcType=JdbcType.VARCHAR),
            @Result(column="Sex", property="sex", jdbcType=JdbcType.VARCHAR),
            @Result(column="Pwd", property="pwd", jdbcType=JdbcType.VARCHAR),
            @Result(column="Phone", property="phone", jdbcType=JdbcType.VARCHAR),
            @Result(column="LoginTime", property="logintime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="LoginIP", property="loginip", jdbcType=JdbcType.VARCHAR),
            @Result(column = "Role", property = "role", jdbcType = JdbcType.VARCHAR),
            @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column = "UpdateTime", property = "updatetime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "AuthToken", property = "authtoken", jdbcType = JdbcType.LONGVARCHAR)
    })
    Student getStudentBySid(String sid);

    @Select({
            "select",
            "id, Sid, Mid, Sname, Sex, Pwd, Phone, LoginTime, LoginIP, Role, CreateTime, ",
            "UpdateTime, AuthToken",
            "from student",
            "where Sname like concat('%',#{sname,jdbcType=VARCHAR},'%')"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Sid", property = "sid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "Mid", property = "mid", jdbcType = JdbcType.VARCHAR),
            @Result(column="Sname", property="sname", jdbcType=JdbcType.VARCHAR),
            @Result(column="Sex", property="sex", jdbcType=JdbcType.VARCHAR),
            @Result(column="Pwd", property="pwd", jdbcType=JdbcType.VARCHAR),
            @Result(column="Phone", property="phone", jdbcType=JdbcType.VARCHAR),
            @Result(column="LoginTime", property="logintime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="LoginIP", property="loginip", jdbcType=JdbcType.VARCHAR),
            @Result(column = "Role", property = "role", jdbcType = JdbcType.VARCHAR),
            @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column = "UpdateTime", property = "updatetime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "AuthToken", property = "authtoken", jdbcType = JdbcType.LONGVARCHAR)
    })
    List<Student> getStudentBySname(String sname);

    @Select({
            "select count(*)",
            "id, Sid, Mid, Sname, Sex, Pwd, Phone, LoginTime, LoginIP, Role, CreateTime, ",
            "UpdateTime, AuthToken",
            "from student",
            "where Sid = #{sid,jdbcType=VARCHAR}"
    })
    Integer getAdminByOneSid(String sid);
}